/*
*排名 table
*RankingsTable.js*/

import React, { PropTypes, Component } from 'react';
import { autobind } from 'core-decorators';
import { Table,Input,Button,Icon } from 'antd';
import { connect } from 'react-redux';
import TablePagination from '../../components/TablePagination';
// const RankingsTable =({dispatch,privateGame})=>{
// 	const {ranksData} = privateGame;
// 	const columns = [
// 		{
// 			title: '备案码',
// 			dataIndex: 'recordCode',
// 			key: 'recordCode',
// 		},
// 		{
// 			title: '产品名称',
// 			dataIndex: 'productName',
// 			key: 'productName',
// 		},
// 		{
//       title: '年化收益',
//       dataIndex: 'returnRate',
//       key: 'returnRate',
//       sorter: (a, b) => a.returnRate - b.returnRate,
//     },
//    	{
//       title: 'Sharpe',
//       dataIndex: 'sharpeRatio',
//       key: 'sharpeRatio',
//       sorter: (a, b) => a.sharpeRatio - b.sharpeRatio,
//     },
// 		{
//       title: '投资策略',
//       dataIndex: 'investStrategy',
//       key: 'investStrategy',
//     }
// 	];

// 	return (
// 		<Table
// 			columns={columns}
// 			dataSource={ranksData}
// 			rowKey={record => record.productId}
// 		/>
// 	)
// }

class RankingsTable extends React.Component {
	constructor(props) {
    super(props);
    console.log(2341111,props)
    this.state = {
    	filterDropdownVisible: false,
	    data:[],
	    searchText: '',
	    filtered: false,
    };
  }
  componentWillMount() {
  	const {ranksData} = this.props;
  	console.log(234,this.props,ranksData)
  	this.setState({
  		data:ranksData
  	})
  }
  componentWillReceiveProps(nextProps) {
  	const {ranksData} = nextProps.privateGame;
  	console.log(234123,nextProps,ranksData)
  	this.setState({
  		data:ranksData
  	})
  }
  onInputChange = (e) => {
    this.setState({ searchText: e.target.value });
  }
  onSearch = () => {
    const { searchText } = this.state;
    const reg = new RegExp(searchText, 'gi');
    this.setState({
      filterDropdownVisible: false,
      filtered: !!searchText,
      data: data.map((record) => {
        const match = record.name.match(reg);
        if (!match) {
          return null;
        }
        return {
          ...record,
          name: (
            <span>
              {record.name.split(new RegExp(`(?<=${searchText})|(?=${searchText})`, 'i')).map((text, i) => (
                text.toLowerCase() === searchText.toLowerCase() ?
                  <span key={i} className="highlight">{text}</span> : text // eslint-disable-line
              ))}
            </span>
          ),
        };
      }).filter(record => !!record),
    });
  }
  render() {
    const columns = [
	    {
				title: '备案码',
				dataIndex: 'recordCode',
				key: 'recordCode',
			},
			{
	      title: '产品名称',
	      dataIndex: 'productName',
	      key: 'productName',
    	},
    	{
	      title: '年化收益',
	      dataIndex: 'returnRate',
	      key: 'returnRate',
	      sorter: (a, b) => a.returnRate - b.returnRate,
    	},
    	{
	    	title: 'Sharpe',
	      dataIndex: 'sharpeRatio',
	      key: 'sharpeRatio',
	      sorter: (a, b) => a.sharpeRatio - b.sharpeRatio,
	    }, 
	    {
	      title: '投资策略',
	      dataIndex: 'investStrategy',
	      key: 'investStrategy',
      	filters: [{
	        text: '股票多头',
	        value: '股票多头',
	      }, {
	        text: '股票多空',
	        value: '股票多空',
	      },{
	        text: '市场中性',
	        value: '市场中性',
	      },{
	        text: '固定收益',
	        value: '固定收益',
	      },{
	        text: 'CTA',
	        value: 'CTA',
	      },{
	        text: '其他',
	        value: '其他',
	      }],
      	onFilter: (value, record) => record.investStrategy.indexOf(value) === 0,
    	}];
    return <Table columns={columns} dataSource={this.state.data} />;
  }
}


export default connect(({privateGame})=>({privateGame}))(RankingsTable)